package com.joeshing.security.authentication.session;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.session.SessionAuthenticationException;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;

import com.joeshing.security.context.CacheSecurityContextRepository;

public class CacheSessionControlStrategy implements
		SessionAuthenticationStrategy {
	
	private CacheSecurityContextRepository securityContextRepository;

	public void setSecurityContextRepository(
			CacheSecurityContextRepository securityContextRepository) {
		this.securityContextRepository = securityContextRepository;
	}


	@Override
	public void onAuthentication(Authentication authentication,
			HttpServletRequest request, HttpServletResponse response)
			throws SessionAuthenticationException {
		securityContextRepository.clearUserContext(authentication.getName());
	}

}
